﻿    $(function () {
        $.getJSON("/Post/LoadDDLCountry", function (countryData) {
            var select = $("#ddlCountry");
            select.empty();
            select.append($('<option/>', {
                value: 0,
                text: "Select a Country"
            }));
            $.each(countryData, function (index, itemData) {

                select.append($('<option/>', {
                    value: itemData.Value,
                    text: itemData.Text
                }));
            });
        });


        $("#ddlCountry").change(function () {
            var idCountry = $(this).val();
            if (idCountry != null && idCountry != '') {
                $.getJSON("LoadDDLStates", { countryId: idCountry }, function (stateData) {
                    var select = $("#ddlState");
                    select.empty();
                    select.append($('<option/>', {
                        value: 0,
                        text: "Select a State"
                    }));
                    $.each(stateData, function (index, itemData) {

                        select.append($('<option/>', {
                            value: itemData.Value,
                            text: itemData.Text
                        }));
                    });

                });
            }
        });

        $("#ddlState").change(function () {
            var idState = $(this).val();
            $.getJSON("/Post/LoadDDLCity", { stateId: idState }, function (cityData) {
                var select = $("#ddlCity");
                select.empty();
                select.append($('<option/>', {
                    value: 0,
                    text: "Select a City"
                }));
                $.each(cityData, function (index, itemData) {

                    select.append($('<option/>', {
                        value: itemData.Value,
                        text: itemData.Text
                    }));
                });
            });
        });
    });